using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Sec_scan漏洞扫描系统.Sec_Service
{
    /// <summary>
    /// 后台扫描服务
    /// </summary>
    public class Sec_PathScan_Service
    {
        /// <summary>
        /// 后台扫描方法
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string PathScan(string path)
        {
            Sec_Api.Sec_PathScan_Service_Api.Path = new StringBuilder();//初始化 Path
            string url = Sec_Api.Sec_PathScan_Service_Api.Url.ToString();//输入URL地址
            string paths = Sec_Api.Sec_PathScan_Service_Api.Path.ToString();//后台地址接口路径，前提条件先把接口读取出来
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + paths);
                request.Method = "GET";
                request.AllowAutoRedirect = false;
                request.KeepAlive = false;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if(response.StatusCode == HttpStatusCode.OK)
                {
                    //能访问表示能打开，把存在的接口进行传出 ，不传出地址
                    Sec_Api.Sec_PathScan_Service_Api.UrlPathOk.Append(paths);
                }
            }
            catch(Exception ex)
            {
                string Exp = ex.ToString();
                Sec_Api.Sec_PathScan_Service_Api.ExpLoTions = Exp.ToString();
            }
            return path;
        }
    }
}
